package com.lg.system.main.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lg.system.main.service.LoginService;
import com.lg.system.menu.entity.Menu;
import com.lg.system.menu.service.MenuService;
import com.lg.utils.BuildTree;
import com.lg.utils.Tree;

/**
 * <p>
 * 用户与角色对应关系 服务实现类
 * </p>
 *
 * @author dl
 * @since 2018-03-23
 */
@Service
public class LoginServiceImpl implements LoginService {
	@Autowired
	MenuService menuService;
	
	@Override
	public List<Tree<Menu>> menus(Long userId) {
		List<Menu>  menus=menuService.selectMenuTreeByUid(userId);
		List<Tree<Menu>> trees = new ArrayList<Tree<Menu>>();
		for (Menu menu : menus) {
			Tree<Menu> tree = new Tree<Menu>();
			tree.setId(menu.getMenuId().toString());
			tree.setParentId(menu.getParentId().toString());
			tree.setName(menu.getName());
			Map<String, Object> attributes = new HashMap<>(16);
			attributes.put("url", menu.getUrl());
			attributes.put("icon", menu.getIcon());
			tree.setAttributes(attributes);
			trees.add(tree);
		}
		List<Tree<Menu>> list = BuildTree.buildList(trees, "0");
		return list;
	}
}
